<template>
	<view class="details">
		<SRV-topbar  :title="pageTitle" isLeft="true"></SRV-topbar>
		<view class="line" v-for="(item,index) in pageResult.list" :key="index">
            <view v-if="pageParam.type != 'intention'" style="position: relative;">
                <view class="status-box" style="position: absolute;right: 120rpx;top: 20rpx;" v-if="pageParam.type == 'merchantCommonly' || pageParam.type == 'merchantJoy'">
                    <show-status :name="item.statusName" size="180" fontSize="50" boder="5"
                        :color="item.status==0 ? '#cc0000' : (item.status==-2 ? '#fbca3f' : (item.status==1 ? '#009900' : '#FF0000')) ">
                    </show-status>
                </view>
                <view class="list-box">
                    <view class="list-left"> {{item.title}} </view>
                    <view class="list-right"> {{item.no}} </view>
                </view>
                <view class="list-box">联系人：<view>{{item.realname}}  </view></view>
                <view class="list-box" @click="callPhone(item.mobile)">
                    联系电话：
                    <view>
                        <image src="https://hdsq.aoorange.cn/attachment/xcx/new_2022/tel.png" mode="aspectFill"></image>
                        {{item.mobile}} 
                    </view>
                </view>
                <view class="list-box">{{item.lastItem}}</view>
				<view class="bot_state" v-if="item.buttonList.length > 0">
				    <text v-for="(button,index3) in item.buttonList" :key="index3" @click="operateFun(button.type, index)" class="sel">
				        {{button.title}}
				    </text>
				</view>
            </view>
            <view v-if="pageParam.type == 'intention'">
                <view class="list-box">联系人：<view>{{item.realname}}  </view></view>
                <view class="list-box" @click="callPhone(item.mobile)">
                    联系电话：
                    <view>
                        <image src="https://hdsq.aoorange.cn/attachment/xcx/new_2022/tel.png" mode="aspectFill"></image>
                        {{item.mobile}} 
                    </view>
                    
                </view>
                <view class="list-box" v-if="item.status == 3">
                    <view class="list-left"> 开通类型：{{item.typeName}} </view>
                    <view class="list-right"> 开通价格：{{item.payMoney}} </view>
                </view>
                <view class="list-box" v-if="item.status == 3">
                    <view class="list-left"> {{item.spread_title}} </view>
                    <view class="list-right"> {{item.spread_no}} </view>
                </view>
                <view class="list-box">
                    <view class="list-left">  </view>
                    <view class="list-right"> 状态：{{item.statusName}} </view>
                </view>
            </view>
        </view>
		<view v-if="pageResult.list.length == 0" class="nocontent">
			<image src="https://hdsq.aoorange.cn/attachment/xcx/new_2022/base.png" mode="widthFix"></image>
			<text>暂无记录～</text>
		</view>
	</view>
</template>

<script>
    var _self;
	import serve from '../../static/request.js';
	import storage from '../../static/appkey.js';
	import common from '../../static/jump.js';
	export default {
		data() {
			return {
                pageTitle: '未开通的客户',
                typeList: {
                    intention: '待开通的客户',
                    openStore : '店主列表',
                    openAgent: '代理列表',
                    openGeneration: '总代列表',
                    merchantCommonly: '一般商户列表',
                    merchantJoy: '娱乐商户列表',
                },
				pageParam: {
					appkey: uni.getStorageSync('appkey'),
					'access-token': uni.getStorageSync('access-token'),
					type: '',
					page: 0,
				},
				pageResult: {
					list: [],
					isEmpty: false,
					isEnd: false
				}
			}
		},
		methods: {
			getList(){
				_self.pageParam.page++
				serve.request({
                    url: '/member/batch/list',
                    data: _self.pageParam,
                    v: '/v2'
                }).then(res => {
                    console.log(res.data); 
                    if (res.data && res.data.length > 0) {
                        _self.pageResult.list = _self.pageResult.list.concat(res.data);
                    }
                    _self.pageResult.isEmpty = _self.pageResult.list.length == 0;
                    _self.pageResult.isEnd = res.data.length == 0; 
                });
			},
			operateFun(type, key){
				let operateItem = this.pageResult.list[key];
				if (type == 'subTask') {
					uni.showModal({
					    title: '提示',
					    content: '您确定该邀请提交工作吗',
					    success: function(res) {
					        if (res.confirm) {
				                _self.finishFun('/member/batch/sub-task', key, operateItem.id);
					        }
					    }
					});
					return;
				} else if (type == 'drawAchievement') {
					uni.showModal({
					    title: '提示',
					    content: '您确定领取该邀请的业绩吗',
					    success: function(res) {
					        if (res.confirm) {
                                _self.finishFun('/member/batch/draw-achievement', key, operateItem.id);
					        }
					    }
					});
					return;
                } 
			},
			finishFun(funishUrl, operateKey, operateId) {
			    serve.request({
			        url: funishUrl,
			        data: {
			            appkey: uni.getStorageSync('appkey'),
			            'access-token': uni.getStorageSync('access-token'),
			            id: operateId,
			        },
			        v: '/v2'
			    }).then(res => {
			        uni.showToast({
			            title: res.message,
			            icon: 'none'
			        });
			        if (res.code == 200) {
						this.pageResult.list[operateKey].buttonList = [];
			            this.$forceUpdate();
			        }
			    });
			},
			// 快捷拨打电话
			callPhone(mobile) {
				uni.makePhoneCall({
				    phoneNumber: mobile
				});
			}
		},
		onLoad(options) {
            _self = this;
			_self.pageParam.type = options.type || '';
            if(_self.pageParam.type == '') {
                uni.showToast({
                	title: '参数错误',
                	icon: 'none',
                	success() {
                		setTimeout(function() {
                			common.jump('return_one');
                		}, 1000)
                	}
                });
                return ;
            }
            _self.pageTitle = _self.typeList[_self.pageParam.type];
			_self.getList();
		},
		onPullDownRefresh() {
			_self.pageParam.page = 0;
			_self.pageResult.list = [];
			_self.getList();
		},
		onReachBottom() {
			if(_self.pageResult.isEnd || _self.pageResult.isEmpty){
				return ;
			}
			_self.getList()
		}
	}
</script>

<style scoped lang="scss">
	.details {
		width: 100%;
        .line {
            border: 2rpx solid #aaaaaa;
            margin: 20rpx;
        }
        
        .list-box {
        	border-bottom: 2rpx solid #eaeaea;
        	display: flex;
        	justify-content: space-between;
        	align-content: center;
        	padding: 30rpx 20rpx;
            
            image {
            	width: 40upx;
            	height: 40upx;
                margin-right: 20rpx;
            }
        }
		
		
		.nocontent{
			width: 100%;
			padding-top: 338upx;
			display: flex;
			flex-direction: column;
			align-items: center;
			image{
				width:125upx;
				height:124upx;
			}
			text{
				font-size:28upx;
				color:rgba(204,204,204,1);
			     margin-top: 30upx;
			}
		}
		.bot_state {
		    display: flex;
		    justify-content: flex-end;
		
		    text {
		        width: 200upx;
		        height: 68upx;
		        line-height: 68upx;
		        text-align: center;
		        background: rgba(255, 255, 255, 1);
		        border: 1upx solid rgba(251, 202, 63, 1);
		        border-radius: 34upx;
		        font-size: 34upx;
		        color: rgba(251, 202, 63, 1);
		        margin: 40upx;
		    }
		
		    .sel {
		        background: rgba(251, 202, 63, 1);
		        color: #FFFFFF;
		    }
		}
	}
</style>
